/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.manage.core.processor.active;

import info.peigen.hotpot.common.service.base.ServiceOrderBase;
import info.peigen.hotpot.manage.core.domain.Relation;
import info.peigen.hotpot.manage.core.service.order.RelationEditOrder;
import info.peigen.hotpot.manage.core.service.processor.AbstractHotpotManageServiceProcessor;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import org.noear.solon.annotation.Component;

/**
 * <b>(RelationActiveProcessor)</b>
 * "关联关系" 激活处理器
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2024-06-22
 */
@SuppressWarnings("rawtypes")
@Component
public class RelationActiveProcessor extends AbstractHotpotManageServiceProcessor implements Processor {
    @Override
    public Integer level() {
        return 21;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        switchOrder(serviceContext);
    }

    private void switchOrder(ProcessorServiceContext serviceContext) {
        ServiceOrderBase contextOrder = serviceContext.getOrder();
        if (contextOrder instanceof RelationEditOrder order) {
            Relation domain = relationRepository.active(order.getRelationId());

            serviceContext.setDomain(domain);
        }

    }

}